﻿using System;
using CommunityToolkit.Mvvm.ComponentModel;
using RotovapPlatform.Domain.Business.Machine.Enums;
using RotovapPlatform.Domain.Business.Storage.Entities.Bottles;

namespace RotovapPlatform.UI.ViewModels.MaterialManagement
{
	public partial class ShelfSlotViewModel : ObservableObject
	{
		public int Position { get; }
		public int Layer { get; }

		[ObservableProperty]
		private bool _isSelected;

		[ObservableProperty]
		private Bottle _bottle;

		[ObservableProperty]
		private bool _isOccupied;

		[ObservableProperty]
		public int _locationId;

		// 添加DisplayPosition属性，用于在DataGrid中显示
		public string DisplayPosition { get; set; }

		public ShelfSlotViewModel(int position, int layer)
		{
			Position = position;
			Layer = layer;
			DisplayPosition = $"{layer}-{position + 1}"; // 初始化DisplayPosition
		}

		// 设置瓶子并更新占用状态
		public void SetBottle(Bottle bottle)
		{
			Bottle = bottle;
			IsOccupied = bottle != null;

			// 手动触发属性变更通知，确保UI更新
			OnPropertyChanged(nameof(Bottle));
			OnPropertyChanged(nameof(IsOccupied));
			OnPropertyChanged(nameof(DisplayPosition));
		}

		// 清除瓶子
		public void ClearBottle()
		{
			Bottle = null;
			IsOccupied = false;
			LocationId = 0;
			DisplayPosition = $"{Layer}-{Position + 1}"; // 保留位置显示，但清除瓶子信息

			// 手动触发属性变更通知，确保UI更新
			OnPropertyChanged(nameof(Bottle));
			OnPropertyChanged(nameof(IsOccupied));
			OnPropertyChanged(nameof(LocationId));
			OnPropertyChanged(nameof(DisplayPosition));
		}
	}
}